package com.nuoniu.sibanyun.mapper.provider;

import com.nuoniu.sibanyun.entity.crm.CrmDefineField;
import com.nuoniu.sibanyun.entity.crm.CrmQuotedPrice;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.jdbc.SQL;

/**
 * @auther 小啊刚
 * @date 2020/5/23
 */
public class CrmQuotedMapperProvider {

    /**对应数据库表名**/
    private String TABLE_NAME = "crm_quoted_price";

    /**
     * 获取字段列表
     * @author 小啊刚
     * @date 2020/5/23
     */
    public String quotedPriceList(CrmQuotedPrice price) {
        return new SQL() {
            {
                SELECT("p.*");
                FROM("pub_customer c");
                LEFT_OUTER_JOIN("crm_quoted_price p on c.id = p.crm_id");
                if(StringUtils.isNotBlank(price.getCrmName())){
                    WHERE("crm_name = #{price.crmName}");
                }
                if(StringUtils.isNotBlank(price.getQuotedPriceCode())){
                    WHERE("quoted_price_code = #{price.quotedPriceCode}");
                }
                if(StringUtils.isNotBlank(price.getQuotedPriceBy())) {
                    WHERE("quoted_price_by = #{price.quotedPriceBy}");
                }
                if(price.getStatus() != null) {
                    WHERE("status = #{price.status}");
                }
                ORDER_BY("create_date desc");
            }
        }.toString();
    }
}
